package cn.alusiaor.dic.controller;

import cn.alusiaor.dic.domain.DO.Dic;
import cn.alusiaor.dic.service.IDictService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@Slf4j
@RequestMapping("/dic")
public class DictController {
    @Resource
    private IDictService dictService;

    @GetMapping("")
    public ResponseEntity<Boolean> postDic() {

        Dic statusUse = Dic.builder().dicGroup("status").dicDefault(1).dicName("启用").remark("状态启用").sort(1).dicValue("1").build();
        Dic statusBan = Dic.builder().dicGroup("status").dicDefault(0).dicName("禁用").remark("状态禁用").sort(2).dicValue("2").build();
        dictService.save(statusUse);
        statusUse.setStatus(statusUse);
        dictService.updateById(statusUse);
        dictService.save(statusBan);
        statusBan.setStatus(statusUse);
        dictService.updateById(statusBan);

        Dic sexMan = Dic.builder().dicGroup("sex").dicDefault(1).dicName("男").remark("性别男").sort(1).status(statusUse).dicValue("1").build();
        Dic sexWoman = Dic.builder().dicGroup("sex").dicDefault(0).dicName("女").remark("性别女").sort(2).status(statusUse).dicValue("2").build();
        dictService.save(sexMan);
        dictService.save(sexWoman);
        return new ResponseEntity<>(true, HttpStatus.OK);
    }

    @GetMapping("{id}")
    public ResponseEntity<Dic> getDic(@PathVariable("id") String id) {
        Dic byId = dictService.getById(id);
        return new ResponseEntity<>(byId, HttpStatus.OK);
    }
}
